package com.spx;

import android.graphics.Rect;

public class SpxRect{
	public int left;
	public int top;
	public int right;
	public int bottom;

	public SpxRect(){
		left=0;
		top=0;
		right=0;
		bottom=0;
	}

	public SpxRect(SpxRect rect){
		setRect(rect);
	}

	public SpxRect(int left,int top,int right,int bottom){
		setRect(left,top,right,bottom);
	}

	public void setRect(SpxRect rect){
		if(rect!=null){
			this.left=rect.left;
			this.top=rect.top;
			this.right=rect.right;
			this.bottom=rect.bottom;
		}else{
			left=0;
			top=0;
			right=0;
			bottom=0;
		}
	}

	public void setRect(int left,int top,int right,int bottom){
		this.left=left;
		this.top=top;
		this.right=right;
		this.bottom=bottom;
	}

	public int getLeft(){
		return left;
	}
	
	public int getTop(){
		return top;
	}
	
	public int getWidth(){
		if(left<right){
			return right-left;
		}
		return left-right;
	}

	public int getHeight(){
		if(top<bottom){
			return bottom-top;
		}
		return top-bottom;
	}
	
	/*返回碰撞矩形*/
	public Rect getRect(){
		Rect rect = new Rect();
		rect.left = left;
		rect.top = top;
		rect.right = right;
		rect.bottom = bottom;
		return rect;
	}

	public boolean equals(SpxRect rect){
		if(rect==null){
			return false;
		}
		if((left!=rect.left)||(top!=rect.top)||(right!=rect.right)||(bottom!=rect.bottom)){
			return false;
		}
		return true;
	}

	public boolean isEmpty(){
		if((left==right)||(top==bottom)){
			return true;
		}
		return false;
	}

	public void translate(int x,int y){
		this.left+=x;
		this.top+=y;
		this.right+=x;
		this.bottom+=y;
	}

	public void transform(int transform){
		if(transform==LTrans.TRANS_NONE){
			return;
		}
		int temp;
		if((transform&LTrans.TRANS_X_FLIP)!=0){
			left=-left;
			right=-right;
		}
		if((transform&LTrans.TRANS_Y_FLIP)!=0){
			top=-top;
			bottom=-bottom;
		}
		if((transform&LTrans.TRANS_INVERTED_AXES)!=0){
			temp=left;
			left=top;
			top=temp;
			temp=right;
			right=bottom;
			bottom=temp;
		}
	}

	public void normalize(){
		int temp;
		if(left>right){
			temp=left;
			left=right;
			right=temp;
		}
		if(top>bottom){
			temp=top;
			top=bottom;
			bottom=temp;
		}
	}
}